package com.dao.impl;

import java.util.List;

import dao.IProductDao;
import com.wecollege.business.dao.impl.HibernateDaoSupport;
import com.wecollege.domain.Course;

public class ProductDao extends HibernateDaoSupport implements IProductDao{
		
		public Product get(Integer id){
			return getHibernateTemplate().get(Product.class, id);
		}
		
		public Integer save(Product product){
			return (Integer)getHibernateTemplate()
				.save(product);
		}
		
		public void update(Product product){
			getHibernateTemplate().update(product);
		}
		
		public void delete(Product product){
			getHibernateTemplate().delete(product);
		}
		
		public void delete(Integer id){
			getHibernateTemplate().delete(get(id));
		}
		
		public List<Product> findAll(){
			return (List<Product>)getHibernateTemplate()
					.find("from Product");
		}
		
		@Override
		public List<Product> findByParam(String key) {
			String hql = "from Product p where p.pname like '%" + key + "%' or p.productCategory like '%" + key + "%'";
			return this.getSession()
					.createQuery(hql)
					.list();
		}



	}


